from flask import Flask, request, send_from_directory, jsonify, render_template_string
import os

app = Flask(__name__)

@app.route('/files', methods=['GET'])
def files_page():
    files = os.listdir(UPLOAD_FOLDER)
    file_urls = [
        {
            'filename': filename,
            'url': f'http://{request.host}/uploads/{filename}'
        }
        for filename in files
    ]
    html = '''
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Uploaded Files</title>
        <style>
            body { font-family: Arial, sans-serif; margin: 40px; }
            table { border-collapse: collapse; width: 60%; }
            th, td { border: 1px solid #ddd; padding: 8px; }
            th { background: #f2f2f2; }
            tr:hover { background: #f5f5f5; }
            a { color: #007bff; text-decoration: none; }
            a:hover { text-decoration: underline; }
        </style>
    </head>
    <body>
        <h2>Uploaded Files</h2>
        <table>
            <tr><th>Filename</th><th>Download Link</th></tr>
            {% for file in files %}
            <tr>
                <td>{{ file.filename }}</td>
                <td><a href="{{ file.url }}" target="_blank">Download</a></td>
            </tr>
            {% endfor %}
        </table>
    </body>
    </html>
    '''
    return render_template_string(html, files=file_urls) 